package com.dz.server.service.impl;

import com.dz.server.mapper.AtomicMapper;
import com.dz.server.mapper.ProductAtomicMapper;
import com.dz.server.pojo.Atomic;
import com.dz.server.pojo.Product;
import com.dz.server.mapper.ProductMapper;
import com.dz.server.service.ProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dz
 * @since 2022-03-23
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
    @Autowired
    private ProductAtomicMapper productAtomicMapper;
    @Autowired
    private AtomicMapper atomicMapper;
    @Override
    public String getAtomics(Integer pid) {
        List<Integer> atomicIdList = productAtomicMapper.getAtomicId(pid);
        StringBuilder sb = new StringBuilder();
        int size = atomicIdList.size();
        for (int i = 0; i <size - 1; i++) {
            Atomic atomic = atomicMapper.selectById(atomicIdList.get(i));
            sb.append(atomic.getServeName()).append("->");
        }
        sb.append(atomicMapper.selectById(atomicIdList.get(size-1)).getServeName());
        return sb.toString();
    }
}
